package smsapi.api;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import smsapi.ApiException;
import smsapi.model.GetSignRes;

@Component 
public class SignApi extends ApiBase {
	final String localVarPath = "/api/sign";
	
	public GetSignRes GetSignList(String timestamp, String nonce, String token) throws ApiException {
		final StringBuilder url = new StringBuilder();
		url.append(basepath).append(localVarPath);
		HttpHeaders headers = null;
		GetSignRes signRes = new GetSignRes();
		
		try {
			headers = getHttpHeaders(null, timestamp, nonce, token);
		} catch (ApiException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		
		if(headers != null) {
			HttpEntity<?> entity = new HttpEntity<>(null, headers);
			ResponseEntity<GetSignRes> resultResponseEntity = restTemplate.exchange(url.toString(), HttpMethod.GET, entity, GetSignRes.class);
			if (resultResponseEntity.getStatusCode() == HttpStatus.OK) {
				signRes = resultResponseEntity.getBody();
	        } else {
	            throw new ApiException(resultResponseEntity.getStatusCodeValue(), resultResponseEntity.getStatusCode().getReasonPhrase(), null, resultResponseEntity.getBody().toString());
	        }
		}
		return signRes;
	}
}
